package cn.wolfcode.luowowo;

import cn.wolfcode.luowowo.website.controller.CheckLoginInterceptor;
import cn.wolfcode.luowowo.website.param.UserInfoArgumentResolver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;


@SpringBootApplication
public class Website implements WebMvcConfigurer{
    //添加登录的拦截器的配置bean
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(checkLoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/userRegist")
                .excludePathPatterns("/userLogin")
                .excludePathPatterns("/regist.html")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/images/**")
                .excludePathPatterns("/js/**")
        ;

    }
    //加入我们自定义的对象参数注入的方式，贴有UserParam注解的并且注入参数为UserInfo类型，就会从redis缓存中将UserInfo对象获取出来
    //并注入该参数
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
         resolvers.add(userInfoArgumentResolver());
    }

    @Bean
    public UserInfoArgumentResolver userInfoArgumentResolver(){
        return new UserInfoArgumentResolver();
    }

    @Bean
    public CheckLoginInterceptor checkLoginInterceptor(){
        return new CheckLoginInterceptor();
    }


    public static void main(String[] args) {
        System.setProperty("es.set.netty.runtime.available.processors", "false");
        SpringApplication.run(Website.class,args);
    }
}
